package com.zkane.config;

import org.springframework.security.oauth2.common.exceptions.InvalidClientException;
import org.springframework.security.oauth2.provider.ClientDetails;
import org.springframework.security.oauth2.provider.client.BaseClientDetails;
import org.springframework.security.oauth2.provider.client.JdbcClientDetailsService;
import org.springframework.stereotype.Component;

import javax.sql.DataSource;
import java.util.Arrays;

/**
 * @author hzq
 * @date 2021/6/4 15:42
 */
@Component
public class MyJdbcClientDetailsService extends JdbcClientDetailsService {


    public MyJdbcClientDetailsService(DataSource dataSource) {
        super(dataSource);
    }

    @Override
    public ClientDetails loadClientByClientId(String clientId) throws InvalidClientException {
        BaseClientDetails baseClientDetails = new BaseClientDetails();
        baseClientDetails.setClientId(clientId);
        baseClientDetails.setClientSecret("{noop}secret");
        baseClientDetails.setScope(Arrays.asList("all"));
        baseClientDetails.setAuthorizedGrantTypes(Arrays.asList("password,authorization_code,refresh_token,implicit,client_credentials".split(",")));
        baseClientDetails.setAutoApproveScopes(Arrays.asList("true"));
        return baseClientDetails;
    }
}
